package com.cloud.logger.zchain.zchainserver.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.cloud.logger.zchain.zchainserver.entity.propertyenum.MailSendTypeEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;

/**
 * 浙江卓锐科技股份有限公司
 *
 * @author zhengyt
 * @create 2017/11/15
 * @description
 */
@Data
@Document
public class MailFailure {
    @Id
    private String id;
    @ApiModelProperty(name = "address", notes = "邮箱地址", example = "999999@qq.com")
    private String address;
    @ApiModelProperty(name = "content", notes = "邮件内容", example = "3344")
    private String content;
    @JsonProperty("create_time")
    @JSONField(name = "create_time", format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(name = "create_time", notes = "创建时间", example = "2017-11-09 09:01:01")
    private Date createTime;
    @JsonProperty("code")
    @JSONField(name = "code")
    @ApiModelProperty(name = "code", notes = "编码", example = "1")
    @NotBlank(message ="code字段不能为空")
    private String code;

    @JsonProperty("ip")
    @JSONField(name = "ip")
    @ApiModelProperty(name = "ip", notes = "安装ip地址", example = "10.0.0.1")
    private String ip;

    @JsonProperty("port")
    @JSONField(name = "port")
    @ApiModelProperty(name = "port", notes = "端口", example = "8080")
    private String port;

    @JsonProperty("send_time")
    @JSONField(name = "send_time", format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(name = "send_time", notes = "发送时间", example = "2017-11-09 09:01:01")
    private Date sendTime;

    @JsonProperty("mail_send_type")
    @JSONField(name = "mail_send_type")
    @ApiModelProperty(name = "mail_send_type", notes = "发送类型(邮件/短信)", example = "邮件")
    private MailSendTypeEnum mailSendType;

    public MailFailure mailFailure(MailSuccess success){
        this.address = success.getAddress();
        this.content = success.getContent();
        this.createTime = success.getCreateTime();
        this.code = success.getCode();
        this.ip = success.getIp();
        this.port = success.getPort();
        return this;

    }
}